package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TSale;
import com.ruoyi.system.service.ITSaleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 销售 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-08
 */
@Controller
@RequestMapping("/system/tSale")
public class TSaleController extends BaseController
{
    private String prefix = "system/tSale";
	
	@Autowired
	private ITSaleService tSaleService;
	
	@RequiresPermissions("system:tSale:view")
	@GetMapping()
	public String tSale(ModelMap mmap)
	{
		if(!String.valueOf(ShiroUtils.getSysUser().getDeptId()).equals("100")){
			mmap.put("deptId",ShiroUtils.getSysUser().getDeptId());
		}
	    return prefix + "/tSale";
	}
	
	/**
	 * 查询销售列表
	 */
	@RequiresPermissions("system:tSale:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TSale tSale)
	{
		startPage();
        List<TSale> list = tSaleService.selectTSaleList(tSale);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出销售列表
	 */
//	@RequiresPermissions("system:tSale:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSale tSale)
    {
    	List<TSale> list = tSaleService.selectTSaleList(tSale);
        ExcelUtil<TSale> util = new ExcelUtil<TSale>(TSale.class);
        return util.exportExcel(list, "销售数据");
    }
	
	/**
	 * 新增销售
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存销售
	 */
	@RequiresPermissions("system:tSale:add")
	@Log(title = "销售", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TSale tSale)
	{		
		return toAjax(tSaleService.insertTSale(tSale));
	}

	/**
	 * 修改销售
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		TSale tSale = tSaleService.selectTSaleById(id);
		mmap.put("tSale", tSale);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存销售
	 */
	@RequiresPermissions("system:tSale:edit")
	@Log(title = "销售", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TSale tSale)
	{		
		return toAjax(tSaleService.updateTSale(tSale));
	}
	
	/**
	 * 删除销售
	 */
	@RequiresPermissions("system:tSale:remove")
	@Log(title = "销售", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tSaleService.deleteTSaleByIds(ids));
	}
	
}
